<template>
  <div style="">
    <Header :left="true" leftText="返回" title="新增生产异常上报"> </Header>
    <NoticeBar color="#1989fa" background="#ecf9ff" style="margin-top: 5px; font-size: 15px; font-weight: bold"
      left-icon="description">基本信息</NoticeBar>

    <van-form :style="autoHeight" @submit="onSubmit">
      <van-field required readonly class="formstyle" name="picker" :value="valueMachineID" label="设备代码"
        placeholder="点击选择设备代码" @click="showPickerMachineID = true" style="font-weight: bold" />

      <van-popup v-model="showPickerMachineID" position="bottom">
        <van-picker show-toolbar :columns="columnsMachineID" @confirm="onConfirmMachineID"
          @cancel="showPickerMachineID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.MachineName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field required readonly class="formstyle" name="picker" :value="valueAbnormalTypeID" label="异常类型"
        placeholder="点击选择异常类型" @click="showPickerAbnormalTypeID = true" style="font-weight: bold" />
      <van-popup v-model="showPickerAbnormalTypeID" position="bottom">
        <van-picker show-toolbar :columns="columnsAbnormalTypeID" @confirm="onConfirmAbnormalTypeID"
          @cancel="showPickerAbnormalTypeID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.AbnormalTypeName }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field required readonly clickable class="formstyle" name="datetimePicker" :value="form.OccurDatetime"
        label="异常发生时间" placeholder="选择时间" style="font-weight: bold" @click="showPickerOccurDatetime = true" />
      <van-popup v-model="showPickerOccurDatetime" position="bottom">
        <van-datetime-picker type="datetime" @confirm="onConfirmOccurDatetime" @cancel="showPickerOccurDatetime = false"
          :min-date="minDate" :max-date="maxDate" :value="currentdate" />
      </van-popup>

      <van-field required readonly class="formstyle" name="picker" :value="valuepShiftName" label="班次选择"
        placeholder="点击选择班次" style="font-weight: bold" @click="showPickerpShiftID = true" />
      <van-popup v-model="showPickerpShiftID" position="bottom">
        <van-picker show-toolbar :columns="columnsshift" @confirm="onConfirmpShiftID"
          @cancel="showPickerpShiftID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.pshiftname }}</div>
            </div>
          </template>
        </van-picker>
      </van-popup>

      <van-field required readonly class="formstyle" name="picker" :value="valuepPOrderID" label="生产订单"
        placeholder="点击选择生产订单" @click="showPickerPOrderID = true" style="font-weight: bold" />
      <van-popup v-model="showPickerPOrderID" position="bottom">
        <van-picker show-toolbar :columns="columnsPOrderIDND" @confirm="onConfirmPOrderID"
          @cancel="showPickerPOrderID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.POrderIDAndMaterialName }}</div>
            </div>

          </template>
          <template #title>
            <van-field v-model="searchKey1" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>
      <van-field class="formstyle" required readonly v-model="form.MaterialID" name="物料代码" label="物料代码" placeholder=""
        style="font-weight: bold" />
      <van-field class="formstyle" required readonly v-model="form.MaterialName" name="物料名称" label="物料名称" placeholder=""
        style="font-weight: bold" />
      <van-field v-model="form.AbnormalDescription" class="formstyle" rows="4" autosize label="异常信息描述" type="textarea"
        maxlength="150" placeholder="输入异常信息描述" show-word-limit style="font-weight: bold" />

      <NoticeBar color="#1989fa" v-if="ShowMachineExceptionType" background="#ecf9ff"
        style="margin-top: 5px; font-size: 15px; font-weight: bold" left-icon="description">机器设备异常</NoticeBar>
      <van-row style="margin-left: 10px; margin-top: 10px;margin-bottom: 10px;" v-if="ShowMachineExceptionType">
        <van-col class="formstyle" style="font-weight:normal;font-size: medium"><a style="color: red">*</a>设备状态:</van-col>
        <van-col v-show="showMachineStatusColColor" id="MachineStatusCol" class="formstyle" style="color: #bold"
          @click="showPickerMachineStatus = true">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{
            valueMachineStatus
          }}</van-col>
        <van-col v-show="!showMachineStatusColColor" id="MachineStatusCol" class="formstyle" style="color: #b2b2b2"
          @click="showPickerMachineStatus = true">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{
            valueMachineStatus
          }}</van-col>
        <van-popup v-model="showPickerMachineStatus" position="bottom">
          <van-picker show-toolbar :columns="columnsMachineStatus" @confirm="onConfirmMachineStatus"
            @cancel="showPickerMachineStatus = false" />
        </van-popup>
        <van-col offset="4" class="formstyle" style="font-size: medium;font-weight: normal">对质量影响:</van-col>
        <van-col v-if="showQualityEffectColColor" id="QualityEffectCol" class="formstyle"
          @click="showPickerQualityEffect = true" style="color: #bold">{{ valueQualityEffect }}</van-col>
        <van-col v-show="!showQualityEffectColColor" id="QualityEffectCol" class="formstyle"
          @click="showPickerQualityEffect = true" style="color: #b2b2b2">{{ valueQualityEffect }}</van-col>
        <van-popup v-model="showPickerQualityEffect" position="bottom">
          <van-picker show-toolbar :columns="columnsQualityEffect" @confirm="onConfirmQualityEffects"
            @cancel="showPickerQualityEffect = false" />
        </van-popup>
      </van-row>

      <van-field required readonly v-show="ShowMachineExceptionType" class="formstyle" name="picker"
        :value="valueSafeEffect" label="对安全影响" placeholder="点击选择对安全影响" @click="showPickerSafeEffect = true"
        style="font-weight: bold" />
      <van-popup v-model="showPickerSafeEffect" position="bottom">
        <van-picker show-toolbar :columns="columnsSafeEffect" @confirm="onConfirmSafeEffect"
          @cancel="showPickerSafeEffect = false" />
      </van-popup>

      <van-field class="formstyle" required v-if="ShowMachineExceptionType" v-model="form.AbnormalLevl" name="异常等级"
        label="异常等级" placeholder="点击选择" style="font-weight: bold" />
      <van-field v-model="form.Memo" rows="4" v-if="ShowMachineExceptionType" autosize label="异常备注信息" type="textarea"
        maxlength="150" placeholder="输入异常备注信息" show-word-limit style="font-weight: bold" />

      <NoticeBar color="#1989fa" background="#ecf9ff" v-if="ShowDataCollectionItemExceptionType"
        style="margin-top: 5px; font-size: 15px; font-weight: bold" left-icon="description">工艺参数异常</NoticeBar>

      <van-field required readonly class="formstyle" name="picker" :value="valueDataCollectionItemID"
        v-if="ShowDataCollectionItemExceptionType" label="异常参数代码" placeholder="点击选择异常参数代码"
        @click="showPickerDataCollectionItemID = true" style="font-weight: bold" />
      <van-popup v-model="showPickerDataCollectionItemID" position="bottom">

        <van-picker show-toolbar :columns="searchColumns" @confirm="onConfirmDataCollectionItemID"
          @cancel="showPickerDataCollectionItemID = false">
          <template #option="option">
            <div style="display: flex; flex-direction: column; align-items: center">
              <div>{{ option.DataCollectionItemName }}</div>
            </div>
          </template>
          <template #title>
            <van-field v-model="searchKey" placeholder="请输入搜索内容" clearable />
          </template>
        </van-picker>
      </van-popup>

      <van-field class="formstyle" required v-model="form.HighLevel" v-if="ShowDataCollectionItemExceptionType"
        name="参数上限标准" label="参数上限标准" placeholder="输入参数上限标准" style="font-weight: bold" />
      <van-field class="formstyle" v-if="ShowDataCollectionItemExceptionType" required v-model="form.LowLevel"
        name="参数下限标准" label="参数下限标准" placeholder="输入参数下限标准" style="font-weight: bold" />
      <van-field v-if="ShowDataCollectionItemExceptionType" class="formstyle" required v-model="form.SetHigh"
        name="参数设定上限值" label="参数设定上限值" placeholder="输入参数设定上限值" style="font-weight: bold" />
      <van-field class="formstyle" v-if="ShowDataCollectionItemExceptionType" required v-model="form.SetLow"
        name="参数设定下限值" label="参数设定下限值" placeholder="输入参数设定下限值" style="font-weight: bold" />
      <van-field class="formstyle" v-if="ShowDataCollectionItemExceptionType" required v-model="form.FactValue"
        name="参数实际值" label="参数实际值" placeholder="输入参数实际值" style="font-weight: bold" />

      <div style="margin: 16px">
        <van-button color="#138087" round block type="info" native-type="submit" @click="submitsure">保存</van-button>
      </div>
    </van-form>
  </div>
</template>
  
<script>
import {
  Col,
  Row,
  Form,
  Cell,
  Icon,
  Field,
  NumberKeyboard,
  Image as VanImage,
  Picker,
  popup,
  SubmitBar,
  Button,
  Loading,
  Overlay,
  Dialog,
  Toast,
  NoticeBar,
  Tag,
  DatetimePicker,
  ImagePreview,
  CellGroup,
  Uploader,
  Cascader,
  Calendar,
  RadioGroup,
  Radio,
  Divider,
  Stepper,
  AddressList,
  Checkbox,
  CheckboxGroup,
} from "vant";

import "vue-easytable/libs/themes-base/index.css";
import { VTable } from "vue-easytable";
import { _httpClient as _httpClientApisie } from "@/libs/apisie";
import { _httpClient as _httpClientApi } from "@/libs/api";
import { getToken, getBaseApiFrefix } from "@/libs/auth";
import Header from "@/components/header.vue";
import { storage } from "@/libs/utils";
import moment from 'moment'; //导入模块
moment.locale('zh-cn'); //设置语言 或 moment.lang('zh-cn'); 
Vue.prototype.$moment = moment;//赋值使用


Vue.use(Form);
Vue.use(Field);
Vue.use(Overlay);
Vue.use(Loading);
Vue.use(Picker);
Vue.use(popup);
Vue.use(SubmitBar);
Vue.use(VanImage);
Vue.use(DatetimePicker);
Vue.use(Cascader);
Vue.use(Calendar);
Vue.use(Cell);
Vue.use(RadioGroup);
Vue.use(Radio);
Vue.use(Divider);
Vue.use(Stepper);
Vue.use(Button);
Vue.use(AddressList);
Vue.use(Checkbox);
Vue.use(CheckboxGroup);
Vue.use(Col);
Vue.use(Row);

export default {
  name: "InsertManualReporting",
  components: {
    Form,
    Row,
    Col,
    Button,
    Header,
    Form,
    Cell,
    Icon,
    Field,
    NumberKeyboard,
    Dialog,
    Toast,
    NoticeBar,
    Row,
    Tag,
    popup,
    DatetimePicker,
    ImagePreview,
    CellGroup,
    Uploader,
    Col,
    Calendar,
    Cascader,
    Picker,
    RadioGroup,
    Radio,
    Divider,
    Stepper,
    VTable,
    AddressList,
    Checkbox,
    CheckboxGroup,
  },
  data() {
    return {
      searchKey1: "",
      searchKey: "",
      searchColumns: [],
      minDate: new Date(2023, 1, 1),
      maxDate: new Date(2025, 10, 1),
      currentdate: new Date(),
      form: {
        AbnormalDescription: ""
      },
      showPickerMachineID: false,
      showPickerQualityEffect: false,
      showPickerSafeEffect: false,
      showPickerMachineStatus: false,
      showPickerPOrderID: false,
      showPickerQualityEffect: false,
      showPickerpShiftID: false,
      showPickerAbnormalTypeID: false,
      showPickerOccurDatetime: false,
      showPickerDataCollectionItemID: false,
      ShowMachineExceptionType: false,
      ShowDataCollectionItemExceptionType: false,
      columnsDataCollectionItemID: [],
      columnsTeamID: [],
      columnsAbnormalTypeID: [],
      columnsPOrderID: [],
      columnsPOrderIDND: [],
      columnsshift: [],
      columnsMachineStatus: ["停机", "不停机"],
      columnsQualityEffect: ["高", "中", "低"],
      columnsSafeEffect: ["高", "低"],
      valueMachineID: "",
      valueDataCollectionItemID: "",
      valueAbnormalTypeID: "",
      valuepShiftName: "",
      valuepPOrderID: "",
      valueMachineStatus: "",
      user: [],
      showeSearch: false,
      showMachineStatusColColor: false,
      showQualityEffectColColor: false,
    };
  },
  created: function () {
    this.user = JSON.parse(storage.get("user"));
    this.form.FactoryID = "TC00";
    this.getMachineID();
    this.getAbnormalTypeID();
    this.getCurrentPShift();
    this.getPOrderID();
    this.getDataCollectionItemID();
    this.form.OccurDatetime = this.getNowTime();
    this.valueMachineStatus = "选择";
    this.valueQualityEffect = "选择";
  },
  mounted() { },
  watch: {  //实时监听搜索输入内容
    'searchKey': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.searchColumns = this.columnsDataCollectionItemID.filter(item => item.DataCollectionItemName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    },
    'searchKey1': {
      handler(newVal) {
        let key = String(newVal);
        //alert(key);
        key = key.replace(/\s*/g, "");
        const reg = new RegExp(key, "ig");
        /* 进行筛选，将筛选后的数据放入新的数组中，‘name’键可根据需要搜索的key进行调整 */
        this.columnsPOrderIDND = this.columnsPOrderID.filter(item => item.POrderIDAndMaterialName.match(reg) != null);
        //alert(this.searchColumns);
      },
      deep: true,
      immediate: true,
    }
  },
  methods: {
    getNowTime() {
      let dateTime;
      let yy = new Date().getFullYear();
      let mm = new Date().getMonth() + 1;
      let dd = new Date().getDate();
      let hh = new Date().getHours();
      let mf =
        new Date().getMinutes() < 10
          ? "0" + new Date().getMinutes()
          : new Date().getMinutes();
      let ss =
        new Date().getSeconds() < 10
          ? "0" + new Date().getSeconds()
          : new Date().getSeconds();
      dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
      return dateTime;
    },
    async submitsure() {
      let _this = this;
      if (_this.form.AbnormalTypeID == "") {
        Toast("异常类型不能为空");
        return;
      }
      if (_this.form.MachineID == "") {
        Toast("设备代码不能为空");
        return;
      }
      if (_this.form.PShiftID == "") {
        Toast("班次选择不能为空");
        return;
      }
      // if (_this.checktext == "") {
      //   Toast("任务评价不能为空");
      //   return;
      // }
      try {
        Toast.loading({
          mask: true,
          forbidClick: true,
          duration: 0,
          message: "请稍等...",
        });
        let bodyss = {
          factoryID: "TC00",
          occurDatetime: _this.form.OccurDatetime,
          dataCollectionItemName: _this.form.DataCollectionItemName,
          machineID: _this.form.MachineID,
          abnormalTypeID: _this.form.AbnormalTypeID,
          pShiftID: _this.form.PShiftID,
          pOrderID: _this.form.POrderID,
          materialID: _this.form.MaterialID,
          materialName: _this.form.MaterialName,
          abnormalDescription: _this.form.AbnormalDescription,
          machineStatus: _this.form.MachineStatus,
          qualityEffect: _this.form.QualityEffect,
          safeEffect: _this.form.SafeEffect,
          abnormalLevl: _this.form.AbnormalLevl,
          memo: _this.form.Memo,
          dataCollectionItemID: _this.form.DataCollectionItemID,
          highLevel: _this.form.HighLevel,
          lowLevel: _this.form.LowLevel,
          setLow: _this.form.SetLow,
          setHigh: _this.form.SetHigh,
          factValue: _this.form.FactValue,
          creator: _this.user.userName,
          createDatetime: new Date(),
          closed: false,
        };
        try {
          let res = await _httpClientApisie.post(
            _httpClientApisie.getApiPrefix() +
            "/MachineAbnormalSubmited/SaveEntity",
            {
              body: bodyss,
            }
          );
          if (res.Message == null) {
            Toast.clear();
          } else {
            Toast.clear();
            Toast.fail(res.message);
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }

        let eventDescription = "";
        let eventDatetime = "";
        let eventTypeID = "";
        let eventID = "";
        let messageContent = "";
        let msgContentTypeID = "";
        let pLineID = "";
        let machineID = "";
        let pShiftID = "";
        let teamID = "";
        let pOrderID = "";
        let productionBarcode = "";
        let materialBarcode = "";
        let relatedEmployee = "";
        let messageStatus = "";
        let processBatchID = "";
        let beginDatetime = _this.getNowTime();
        let sendFinished = false;
        let closed = false;


        //alert(_this.form.AbnormalLevl);
        if (_this.form.AbnormalTypeID == "AT02") {
          if (_this.form.AbnormalLevl == "A") {
            eventDescription = "设备代码:【 " + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "MF";
            eventID = "MFA";
            messageContent = "设备代码:【 " + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理(人工上报)】";
            msgContentTypeID = "MFA";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
          else if (_this.form.AbnormalLevl == "B") {
            eventDescription = "设备代码:【" + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "MF";
            eventID = "MFB";
            messageContent = "设备代码:【" + _this.valueMachineID + "】发生设备异常：+故障描述:【" + _this.form.AbnormalDescription + "请及时处理(人工上报)】";
            msgContentTypeID = "MFB";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
          else if (_this.form.AbnormalLevl == "C") {
            eventDescription = "设备代码:【" + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "MF";
            eventID = "MFC";
            messageContent = "设备代码:【" + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理(人工上报)】";
            msgContentTypeID = "MFC";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
          else {
            eventDescription = "设备代码:【" + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "MF";
            eventID = "MFD";
            messageContent = "设备代码:【" + _this.valueMachineID + "】发生设备异常；故障描述:【" + _this.form.AbnormalDescription + "请及时处理(人工上报)】";
            msgContentTypeID = "MFD";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
        }
        else {
          if (true) {
            eventDescription = "设备代码:【" + _this.valueMachineID + "】工艺参数超过标准：故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "TFC";
            eventID = "TFC01";
            messageContent = "设备代码:【" + _this.valueMachineID + "】工艺参数超过标准；故障描述:【" + _this.form.AbnormalDescription + "，超出标准，请及时处理(人工上报)】";
            msgContentTypeID = "TFC01";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
          else {
            eventDescription = "设备代码:【" + _this.valueMachineID + "】工艺参数超过标准：故障描述:【" + _this.form.AbnormalDescription + "请及时处理】";
            eventDatetime = _this.getNowTime();
            eventTypeID = "TFC";
            eventID = "TFC01";
            messageContent = "设备代码:【" + _this.valueMachineID + "】工艺参数超过标准常；故障描述:【" + _this.form.AbnormalDescription + "，超出标准，请及时处理(人工上报)】";
            msgContentTypeID = "TFC01";
            pLineID = _this.form.MachineID;
            machineID = _this.form.MachineID;
            pShiftID = _this.form.PShiftID;
            teamID = _this.form.PShiftID;
            pOrderID = _this.form.POrderID;
            productionBarcode = "";
            materialBarcode = "";
            relatedEmployee = "";
            messageStatus = "";
            processBatchID = "";
          }
        }

        let bodysss = {
          eventDescription: eventDescription,
          eventDatetime: eventDatetime,
          eventTypeID: eventTypeID,
          eventID: eventID,
          messageContent: messageContent,
          msgContentTypeID: msgContentTypeID,
          factoryID: "TC00",
          pLineID: pLineID,
          machineID: machineID,
          pShiftID: pShiftID,
          teamID: teamID,
          pOrderID: pOrderID,
          productionBarcode: productionBarcode,
          materialBarcode: materialBarcode,
          relatedEmployee: relatedEmployee,
          messageStatus: messageStatus,
          processBatchID: processBatchID,
          beginDatetime: beginDatetime,
          sendFinished: sendFinished,
          closed: closed
        };
        //alert(JSON.stringify(bodysss));
        try {
          let res = await _httpClientApisie.post(
            _httpClientApisie.getApiPrefix() + "/RealtimeEventMessage/SaveEntity",
            {
              body: bodysss,
            }
          );
          //alert(JSON.stringify(res));
          if (res.Message == null) {
            // Toast.clear();
            Toast.success("发送成功");
            setTimeout(function () {
              _this.$ac.closeWin();
            }, 2000);
          } else {
            //Toast.clear();
            Toast.fail("发送失败");
          }
        } catch (e) {
          Toast.fail(JSON.stringify(e));
        }
      } catch (error) {
        alert(error);
      }
    },
    async getAbnormalLevel() {
      if(this.valueMachineStatus=="选择"||typeof this.valueSafeEffect== undefined ||this.valueQualityEffect=="选择"){
        return
      }
    
      let _this = this;
      // Toast.loading({
      //   mask: true,
      //   forbidClick: true,
      //   duration: 0,
      //   message: "Loading...",
      // });
      //alert(_this.form.MachineStatus+"/"+_this.form.QualityEffect+"/"+_this.form.SafeEffect);
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/AbnormalLevel/GetList?MachineStatus=" +
          _this.form.MachineStatus +
          "&QualityEffect=" +
          _this.form.QualityEffect +
          "&SafeEffect=" +
          _this.form.SafeEffect
        );
        if (res.HttpCode === "200") {
          Toast.clear();
          //alert(JSON.stringify(res.Data));
          for (let index = 0; index < res.Data.length; index++) {
            if (res.Data[index].MachineStatus == _this.form.MachineStatus && res.Data[index].QualityEffect == _this.form.QualityEffect && res.Data[index].SafeEffect == _this.form.SafeEffect) {
              _this.form.AbnormalLevl = res.Data[index].AbnormalLevl;
            }
          }
        }
        this.$forceUpdate();
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }

    },

    // 获取当前时间
    // getNowTime() {
    //   let dateTime;
    //   let yy = new Date().getFullYear();
    //   let mm = new Date().getMonth() + 1;
    //   let dd = new Date().getDate();
    //   let hh = new Date().getHours();
    //   let mf =
    //     new Date().getMinutes() < 10
    //       ? "0" + new Date().getMinutes()
    //       : new Date().getMinutes();
    //   let ss =
    //     new Date().getSeconds() < 10
    //       ? "0" + new Date().getSeconds()
    //       : new Date().getSeconds();
    //   dateTime = yy + "-" + mm + "-" + dd + " " + hh + ":" + mf + ":" + ss;
    //   return dateTime;
    // },
    onConfirmSafeEffect(value, index) {
      this.valueSafeEffect = this.columnsSafeEffect[index];
      this.form.SafeEffect = this.columnsSafeEffect[index];
      this.showPickerSafeEffect = false;
      this.getAbnormalLevel()
     
    },
    onConfirmQualityEffects(value, index) {
      this.showQualityEffectColColor = true;
      this.valueQualityEffect = this.columnsQualityEffect[index];
      this.form.QualityEffect = this.columnsQualityEffect[index];
      this.showPickerQualityEffect = false;
      this.getAbnormalLevel()
     
      this.$forceUpdate();
    },
    onConfirmMachineStatus(value, index) {
      this.showMachineStatusColColor = true;
      this.valueMachineStatus = this.columnsMachineStatus[index];
      this.form.MachineStatus = this.columnsMachineStatus[index];
      this.showPickerMachineStatus = false;
      this.getAbnormalLevel()
      
      this.$forceUpdate();
    },

    onConfirmPOrderID(value, index) {
      this.valuepPOrderID = this.columnsPOrderIDND[index].POrderIDAndMaterialName;
      this.form.POrderID = this.columnsPOrderIDND[index].POrderID;
      this.form.MaterialID = this.columnsPOrderIDND[index].MaterialID;
      this.form.MaterialName = this.columnsPOrderIDND[index].MaterialName;
      this.showPickerPOrderID = false;
    },
    onConfirmDataCollectionItemID(value, index) {
      this.valueDataCollectionItemID =
        this.searchColumns[index].DataCollectionItemName;
      this.form.DataCollectionItemName =
        this.searchColumns[index].DataCollectionItemName;
      this.form.DataCollectionItemID =
        this.searchColumns[index].DataCollectionItemID;
      this.showPickerDataCollectionItemID = false;
    },
    onConfirmAbnormalTypeID(value, index) {
      this.valueAbnormalTypeID =
        this.columnsAbnormalTypeID[index].AbnormalTypeName;
      this.form.AbnormalTypeID =
        this.columnsAbnormalTypeID[index].AbnormalTypeID;

        // alert(this.form.AbnormalTypeID)
      if (this.form.AbnormalTypeID == "AT02") {
        this.ShowMachineExceptionType = true;
        this.ShowDataCollectionItemExceptionType = false;
      } else if (this.form.AbnormalTypeID == "AT03") {
        this.ShowMachineExceptionType = false;
        this.ShowDataCollectionItemExceptionType = true;
      } else {
        this.ShowMachineExceptionType = false;
        this.ShowDataCollectionItemExceptionType = false;
      }
      this.showPickerAbnormalTypeID = false;
    },
    onConfirmOccurDatetime(time) {
      this.tempTime = time;
      this.form.OccurDatetime = `${time.getFullYear()}-${time.getMonth() + 1
        }-${time.getDate()} ${time.getHours().toString().padStart(2, 0)}:${time
          .getMinutes()
          .toString()
          .padStart(2, 0)}`;
      this.showPickerOccurDatetime = false;
    },
    onConfirmMachineID(value, index) {
      this.valueMachineID = this.columnsMachineID[index].MachineName;
      this.form.MachineID = this.columnsMachineID[index].MachineID;
      this.showPickerMachineID = false;
      this.getDataCollectionItemID(this.columnsMachineID[index].MachineID);
    },
    onConfirmpShiftID(value, index) {
      this.valuepShiftName = this.columnsshift[index].pshiftname;
      this.form.PShiftID = this.columnsshift[index].pShiftID;
      this.form.shiftLong = this.columnsshift[index].pShiftTime;
      this.showPickerpShiftID = false;
    },
    async getshift() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/ProductionShift/GetList"
        );
        if (res.HttpCode === "200") {
          for (let index = 0; index < res.Data.length; index++) {
            if (res.Data[index].Actived == false) {
              delete res.Data[index];
            }
          }
          let shiftMap = res.Data.map((item) => ({
            pshiftname: item.PShiftName + " " + item.BeginTime,
            pShiftID: item.PShiftID,
            pShiftTime: item.ShiftLong,
            pBeginTime: item.BeginTime,
          }));
          _this.columnsshift = shiftMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    async getCurrentPShift() {
      let _this = this;
      await this.getshift();
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/ProductionShift/GetCurrentPShift?FactoryID=TC00"
        );
        if (res.HttpCode === "200") {
          this.showShiftIDNameBypBeginTime(res.Data.split("T")[1]);
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },

    showShiftIDNameBypBeginTime(pBeginTime) {
      this.columnsshift.forEach((item) => {
        if (item.pBeginTime === pBeginTime) {
          this.valuepShiftName = item.pshiftname;
          this.form.PShiftID = item.pShiftID;
          this.form.shiftLong = item.pShiftTime;
        }
      });
    },

    async getDataCollectionItemID(a) {
      let _this = this;
      //alert(a);
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() +
          "/MachineDataCollectionItem/GetList"
        );
        if (res.HttpCode === "200") {
          //alert(JSON.stringify(res));
          let shiftMap = res.Data.map((item) => ({
            DataCollectionItemID: item.DataCollectionItemID,
            DataCollectionItemName: item.DataCollectionItemName,
          }));

          // alert(JSON.stringify(res))
          _this.columnsDataCollectionItemID = shiftMap;
          _this.searchColumns = shiftMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getAbnormalTypeID() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/AbnormalType/GetList"
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            AbnormalTypeID: item.AbnormalTypeID,
            AbnormalTypeName: item.AbnormalTypeName,
          }));
          _this.columnsAbnormalTypeID = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getPOrderID() {
      let dateTo = moment(new Date()).format('YYYY-MM-DD');
      let dateFrom = moment(new Date()).subtract(7, 'days').format('YYYY-MM-DD');
      // alert(dateTo);
      // alert(dateFrom);
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/ProductionOrder/GetList?CreateDatetimeFrom=" + dateFrom + "&CreateDatetimeTo=" + dateTo + ""
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            POrderID: item.POrderID,
            MaterialName: item.MaterialName,
            MaterialID: item.MaterialID,
            POrderIDAndMaterialName: item.POrderID + " " + item.MaterialName,
          }));
          _this.columnsPOrderID = teamMap;
          _this.columnsPOrderIDND = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
    async getMachineID() {
      let _this = this;
      try {
        let res = await _httpClientApisie.get(
          _httpClientApisie.getApiPrefix() + "/MachineEquipment/GetList"
        );
        if (res.HttpCode === "200") {
          let teamMap = res.Data.map((item) => ({
            MachineID: item.MachineID,
            MachineName: item.MachineName,
          }));
          _this.columnsMachineID = teamMap;
        }
      } catch (e) {
        Toast.fail(JSON.stringify(e));
      }
    },
  },
};
</script>

<style>
.primary_info_label_div>.primary_info_label_div_row>.van-col:nth-child(2) {
  flex: 1;
  display: flex;
  justify-content: flex-end;
  overflow: auto;
  color: black;
  word-break: break-all;
}

.formstyle1 {
  color: #b2b2b2;
}

.green {
  background-color: #41b883;
}

.blue {
  background-color: #525e35b7;
}
</style>
  